<!DOCTYPE html>
<html>
<head>
    <title>题目管理</title>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
</head>
<body>
    <h1>题目管理</h1>
    <form id="addQuestionForm">
        <input type="text" name="number" placeholder="题目编号" required>
        <input type="text" name="title" placeholder="标题" required>
        <input type="text" name="star" placeholder="难度（简单/中等/困难）" required>
        <textarea name="desc" placeholder="题目描述" required></textarea>
        <textarea name="header" placeholder="预设代码" required></textarea>
        <textarea name="tail" placeholder="测试用例代码" required></textarea>
        <input type="text" name="cpu_limit" placeholder="CPU限制（秒）" required>
        <input type="text" name="mem_limit" placeholder="内存限制（KB）" required>
        <textarea name="test_input" placeholder="测试输入" required></textarea>
        <button type="submit">添加题目</button>
    </form>
    <script>
        $("#addQuestionForm").submit(function(e) {
            e.preventDefault();
            const data = {
                number: $("input[name='number']").val(),
                title: $("input[name='title']").val(),
                star: $("input[name='star']").val(),
                desc: $("textarea[name='desc']").val(),
                header: $("textarea[name='header']").val(),
                tail: $("textarea[name='tail']").val(),
                cpu_limit: $("input[name='cpu_limit']").val(),
                mem_limit: $("input[name='mem_limit']").val(),
                test_input: $("textarea[name='test_input']").val()
            };
            $.post("/admin/add_question", JSON.stringify(data), function(res) {
                alert(res.success ? "添加成功" : "添加失败");
            });
        });
    </script>
</body>
</html>
